<template>
  <div class="edu-page-warp">
    <InnerBreadcrumb v-model="indexKey" :path="breadPath" :showBack="true"  @input="handleInput"/>
    <div v-if="indexKey == '0'">
      <condition-card @reset="reset" @search="onSubmit" label-width="110px">
        <el-row :gutter="24">
          <el-col :span="8">
            <el-form-item :label="$t('label.grade')">
              <el-date-picker
                clearable
                v-model="queryForm.grade"
                value-format="yyyy"
                type="year"
                :placeholder="$t('common.text.all')"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('label.college')">
              <el-select
                filterable
                multiple
                collapse-tags
                style="width:100%"
                clearable
                v-model="queryForm.facultyList"
                @change="handleChangeFaculty"
              >
                <el-option
                  v-for="item in options.faculty"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('label.major')">
              <el-select
                filterable
                style="width:100%"
                multiple
                collapse-tags
                clearable
                v-model="queryForm.professionList"
              >
                <el-option
                  v-for="item in options.profession"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('label.trainingLevel')">
              <el-select
                v-model="queryForm.trainingLevel"
                style="width:100%"
                clearable
              >
                <el-option
                  v-for="item in options.trainingLevel"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('label.trainingCategory')">
              <el-select
                v-model="queryForm.trainingCategory"
                style="width:100%"
                clearable
              >
                <el-option
                  v-for="item in options.trainingCategory"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('dic.degreeType')">
              <el-select
                v-model="queryForm.degreeType"
                style="width:100%"
                clearable
                @change="handleChangeFaculty"
              >
                <el-option
                  v-for="item in options.degreeType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="$t('label.formLearning')">
              <el-select
                v-model="queryForm.formLearning"
                style="width:100%"
                collapse-tags
              >
                <el-option
                  v-for="item in options.formLearning"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="申请原因">
              <el-select
                filterable
                multiple
                collapse-tags
                style="width:100%"
                clearable
                v-model="applyReasonList"
              >
                <el-option
                  v-for="item in options.applyReason"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审核状态">
              <el-select
                filterable
                multiple
                collapse-tags
                style="width:100%"
                clearable
                v-model="approvalStatusList"
              >
                <el-option
                  v-for="item in options.approvalStatus"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </condition-card>
      <el-card shadow="never">
        <div class="edu-page-title">转导师管理列表</div>
        <el-row>
          <el-col :span="4">
            <el-input
              v-model="queryForm.keyWord"
              :placeholder="$t('score.failScoreManage.pleaseInt')"
              @keyup.enter.native="onSubmit"
              style="width:200px"
            >
              <i
                class="el-icon-search"
                slot="suffix"
                style="margin-top:10px;cursor:pointer"
                @click="onSubmit"
              ></i>
            </el-input>
          </el-col>
          <el-col :span="8">
            <div class="empty-box" />
          </el-col>
          <el-col :span="12">
            <div class="float-right">
              <el-button @click="exprotListToTutor">{{$t('message.export')}}</el-button>
              <el-button type="primary" v-if="!isStudent" @click="handleBatchCheck">批量审核</el-button>
              <el-button
                type="primary"
                @click="handleApply"
                v-if="isStudent"
              >{{$t('message.apply')}}</el-button>
            </div>
          </el-col>
        </el-row>
        <edu-table
          :data="students"
          size="mini"
          style="width:100%"
          @page-change="handleCurrentChange"
          :total="queryForm.total_"
          :pageSize="queryForm.pageSize_"
          :pageNum="queryForm.pageNum_"
          @selection-change="handleSelectionChange"
          :order="false"
          key='studentInfo'
        >
          <el-table-column
            :label="$t('label.stuCode')"
            prop="studentId"
            width="90"
          />
          <el-table-column :label="$t('label.stuName')"  prop="studentName" width="80"/>
          <el-table-column :label="$t('label.grade')" prop="grade" width="60"/>
          <el-table-column
            :label="$t('label.college')"
            width="120"
            prop="facultyI18n"
            show-overflow-tooltip
          />
          <el-table-column
            :label="$t('label.major')"
            width="120"
            prop="professionI18n"
            show-overflow-tooltip
          />
          <el-table-column :label="$t('label.trainingLevel')"  prop="trainingLevelI18n" width="80" show-overflow-tooltip/>
          <el-table-column :label="$t('label.trainingCategory')"  prop="trainingCategoryI18n" show-overflow-tooltip/>
          <el-table-column :label="$t('dic.degreeType')" prop="degreeTypeI18n"  show-overflow-tooltip/>
          <el-table-column :label="$t('dic.formLearning')" prop="formLearningI18n"  show-overflow-tooltip/>
          <el-table-column label="原导师" prop="oldTeacher" show-overflow-tooltip/>
          <el-table-column label="转入导师" prop="newTeacherId" show-overflow-tooltip/>
          <el-table-column
            label="申请原因"
            width="120"
            show-overflow-tooltip
            prop="applyReasonI18n"
          />
          <el-table-column label="申请时间" width="120" show-overflow-tooltip>
            <template slot-scope="scope">{{moment(scope.row.applicationTime)}}</template>
          </el-table-column>
          <el-table-column label="审核状态" prop="approvalStatusI18n" width="90" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="当前处理人"  width="160" show-overflow-tooltip v-if="isStudent">
            <template slot-scope="scope">
              <span v-if="['6','7','8'].includes(scope.row.approvalStatus)">{{ scope.row.reviewerName }}</span>
              <span v-else>{{ scope.row.reviewerName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="当前处理人"  width="160" show-overflow-tooltip v-if="!isStudent">
            <template slot-scope="scope">
              <el-button
                v-if="['6','7','8'].includes(scope.row.approvalStatus)"
                type="text"
                @click="showUserGroup(scope.row.reviewer)"
              >{{ scope.row.reviewerName }}</el-button>
              <span v-else>{{ scope.row.reviewerName }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="$t('message.operating')"  width="150" fixed="right">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="scope.row.isApprove == 0"
                @click="handleCheck(scope)"
              >{{$t('message.check')}}</el-button>
              <el-button
                type="text"
                @click="handleDetail(scope)"
              >{{$t('message.detail')}}</el-button>

              <!--当前为学生时，显示编辑和删除和撤回-->
              <template v-if="isStudent">
                <el-button
                  type="text"
                  v-if="scope.row.approvalStatus === '0'"
                  @click="handleEdit(scope)"
                >{{$t('message.edit')}}</el-button>
                <el-button
                  v-if="scope.row.approvalStatus=== '0'"
                  type="text"
                  @click="handleDelete(scope)"
                >{{$t('message.delete')}}</el-button>

                <!-- applyType:1 学生自己申请的 非教务员代申请 -->
                <el-button
                  v-if="scope.row.approvalStatus=== '4' && scope.row.applyType == '1'"
                  type="text"
                  @click="handleWithdraw(scope)"
                >撤回</el-button>
              </template>
            </template>
          </el-table-column>
        </edu-table>
      </el-card>
    </div>
    <!--审核页面 -->
    <div v-if="indexKey == '1'">
      <el-card shadow="never">
        <div v-if="currentStudent">
          <div class="edu-page-title">学生信息</div>
          <hr style="margin:15px 0 10px 0" />
          <el-form
            label-position="right"
            label-width="150px"
            label-suffix="："
            id="stu-info"
          >
            <el-row>
              <el-col :span="colSpan">
                <el-form-item
                  :label="$t('label.stuCode')"
                >{{currentStudent.studentId}}</el-form-item>
              </el-col>
              <el-col :span="colSpan">
                <el-form-item :label="$t('label.stuName')">{{currentStudent.studentName}}</el-form-item>
              </el-col>
              <el-col :span="colSpan">
                <el-form-item
                  :label="$t('label.college')"
                >{{currentStudent.facultyI18n}}</el-form-item>
              </el-col>
              <el-col :span="colSpan">
                <el-form-item
                  :label="$t('label.major')"
                >{{currentStudent.professionI18n}}</el-form-item>
              </el-col>
              <el-col :span="colSpan">
                <el-form-item :label="$t('label.grade')">{{currentStudent.grade}}</el-form-item>
              </el-col>
              <el-col :span="colSpan">
                <el-form-item :label="$t('label.teacherName')">{{currentStudent.oldTeacher}}</el-form-item>
              </el-col>
              <el-col :span="colSpan">
                <el-form-item
                  :label="$t('label.trainingLevel')"
                >{{currentStudent.trainingLevelI18n}}</el-form-item>
              </el-col>
              <el-col :span="colSpan">
                <el-form-item
                  :label="$t('label.trainingCategory')"
                >{{currentStudent.trainingCategoryI18n}}</el-form-item>
              </el-col>
              <el-col :span="colSpan">
                <el-form-item
                  :label="$t('dic.degreeType')"
                >{{currentStudent.degreeTypeI18n}}</el-form-item>
              </el-col>
              <el-col :span="colSpan">
                <el-form-item
                  :label="$t('label.formLearning')"
                >{{currentStudent.formLearningI18n}}</el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <hr style="margin:0 0 15px 0" />
        <!--详情isRead为false 为申请单详情页面-->
        <div v-if="!isRead">
          <div class="edu-page-title">申请明细</div>
          <table class="table-detail">
            <col width="15%" />
            <col width="35%" />
            <col width="15%" />
            <col width="35%" />
            <tr>
              <td class="label">
                <span>申请原因：</span>
              </td>
              <td colspan="3">
                <span>{{currentStudent.applyReasonI18n}}</span>
              </td>
            </tr>
            <tr>
              <td class="label">
                <span>转入导师：</span>
              </td>
              <td colspan="3">
                <span>{{currentStudent.newTeacherId}}</span>
              </td>
            </tr>
            <tr>
              <td class="textarealabel">
                <span>原因说明：</span>
              </td>
              <td colspan="3">
                <span>{{currentStudent.reasonDescri}}</span>
              </td>
            </tr>
            <tr>
              <td class="label">
                <span>申请材料：</span>
              </td>
              <td colspan="3">
                <!-- <div
                  :key="index"
                  v-for="(file,index) in currentStudent.changeTutorEvidList"
                >
                  <a
                    href="#"
                    @click="handleDownLoad(file)"
                  >{{getFileName(file.name)}}</a>
                </div> -->
                <PreviewOffice
                :newFileList="currentStudent.changeTutorEvidList"
                />
              </td>
            </tr>
          </table>
        </div>
        <!--详情isRead为true 为申请单审批页面-->
        <div v-else>
          <div class="edu-page-title">申请明细</div>
          <el-form label-width="150px" label-suffix="：">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="申请原因" :rules="requireRule">
                  <el-select
                    v-model="currentStudent.applyReason"
                    disabled
                    style="width:100%"
                  >
                    <el-option
                      v-for="item in options.applyReason"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="转入导师">
                  <el-input
                    type="text"
                    disabled
                    style="width:100%"
                    v-model="currentStudent.newTeacherId"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="16">
                <el-form-item label="原因说明" :rules="requireRule">
                  <el-input
                    type="textarea"
                    rows="4"
                    disabled
                    maxlength="256"
                    show-word-limit
                    style="width:100%"
                    v-model="currentStudent.reasonDescri"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="申请材料" :rules="requireRule">
                  <!-- <div
                    :key="index"
                    v-for="(file,index) in currentStudent.changeTutorEvidList"
                  >
                    <a
                      href="#"
                      @click="handleDownLoad(file)"
                    >{{getFileName(file.name)}}</a>
                  </div> -->
                  <PreviewOffice
                  :newFileList="currentStudent.changeTutorEvidList"
                  />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </el-card>
      <!--审核提交-->
      <el-card shadow="never" v-if="isRead">
        <div class="edu-page-title">审核</div>
        <el-form
          label-width="150px"
          label-suffix="："
          ref="submitForm"
          :model="submitForm"
          :rules="submitRules"
        >
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="审批意见" prop="suggestion">
                <el-input
                  type="textarea"
                  rows="4"
                  maxlength="256"
                  v-model="submitForm.suggestion"
                  style="width:100%"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="20" >
              <div v-if="isTipsShow" class="el-row-select-top-tips"> 请注意：助学金中导师出资部分由当月导师支付。转出导师预支的资助费用将作为结余经费可用于其他研究生；</div>
              <div v-if="isTipsShow" class="el-row-select-top-tips2">  转入导师需将转入学生后续资助费用一次性预支完成。</div>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24" style="text-align:right">
              <el-button type="danger" @click="handleReject">{{$t('message.reject')}}</el-button>
              <el-button type="primary" @click="handlePass">{{$t('message.pass')}}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>

      <el-card shadow="never" v-if="isShowApproveHistory">
        <div class="edu-page-title">
          审批进度<i class="el-icon-arrow-down hideBtn" style="mar" @click="hideFrom"></i>
        </div>
        <div v-if="hide">
          <edu-table
            :pagination="false"
            style="margin-top:10px"
            :order="false"
            :selection="false"
            :data="currentStudentApproveHistory"
            key='approval'
          >
            <el-table-column :label="$t('message.order')" prop="order_" width="50" />
            <el-table-column label="时间" >
              <template slot-scope="scope">{{moment(scope.row.approvalTime)}}</template>
            </el-table-column>
            <el-table-column label="审批人"  prop="reviewerName"/>
            <el-table-column :label="$t('label.operation')"  prop="processOperat"></el-table-column>/>
            <el-table-column label="节点" prop="processNodes"></el-table-column>/>
            <el-table-column show-overflow-tooltip label="说明"  prop="reasonDescri" />
          </edu-table>
        </div>
      </el-card>
    </div>
    <!--申请/编辑，学生信息与申请明细在不同的el-card中-->
    <div v-if="indexKey=='2'">
      <el-card shadow="never" v-if="currentStudent">
        <div class="edu-page-title">学生信息</div>
        <hr style="margin:15px 0 10px 0" />
        <el-form label-position="right" label-width="150px" label-suffix="：" id="stu-info">
          <el-row>
            <el-col :span="6">
              <el-form-item :label="$t('label.stuCode')">{{currentStudent.studentId}}</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item :label="$t('label.stuName')">{{currentStudent.studentName}}</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                :label="$t('label.college')"
              >{{currentStudent.facultyI18n}}</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                :label="$t('label.major')"
              >{{currentStudent.professionI18n}}</el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item :label="$t('label.grade')">{{currentStudent.grade}}</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="导师">{{currentStudent.oldTeacher}}</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                :label="$t('label.trainingLevel')"
              >{{currentStudent.trainingLevelI18n}}</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                :label="$t('label.trainingCategory')"
              >{{currentStudent.trainingCategoryI18n}}</el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item
                :label="$t('dic.degreeType')"
              >{{currentStudent.degreeTypeI18n}}</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                :label="$t('label.formLearning')"
              >{{currentStudent.formLearningI18n}}</el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <apply-form-to-tutor
        ref="applyForm"
        :isNull = "isNull"
        :teacherName="currentStudent.teacherName"
        :options="options"
        @close="handleReturn"
        @success="handleSave"
        :show-save-btn="true"
        :students="[currentStudent]"
        :edit-form="editForm"
      />
    </div>
    <edu-dialog title="批量审核" ref="batchApproveDialog" width="500px">
      <el-row>
        <el-col :span="4">审批意见：</el-col>
        <el-col :span="20">
          <el-form ref="batchForm" :model="batchForm" :rules="batchRules">
            <el-form-item prop="suggestion">
              <el-input
                type="textarea"
                v-model="batchForm.suggestion"
                rows="4"
                maxlength="400"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <template slot="buttons">
        <el-button @click="handleBatchCancel">{{$t('message.cancel')}}</el-button>
        <el-button @click="handleBatchReject" type="danger">{{$t('message.reject')}}</el-button>
        <el-button @click="handleBatchPass" type="primary">{{$t('message.pass')}}</el-button>
      </template>
    </edu-dialog>
    <el-dialog v-drag-dialog title="组内用户明细" :visible.sync="showUserGroupDialog">
      <edu-table
        :total="queryUserForm.total"
        @page-change="pageChangeDialog"
        :data="usersUnderGroup"
        :selection="false"
      >
        <el-table-column label="账号">
          <template slot-scope="scope">{{ scope.row.studentId }}</template>
        </el-table-column>
        <el-table-column label="用户名">
          <template slot-scope="scope">{{ scope.row.name }}</template>
        </el-table-column>
        <el-table-column label="联系电话">
          <template slot-scope="scope">{{ scope.row.phoneNumber }}</template>
        </el-table-column>
        <el-table-column label="联系邮箱" min-width="150">
          <template slot-scope="scope">{{ scope.row.email }}</template>
        </el-table-column>
        <el-table-column label="类型">
          <template slot-scope="scope">
            {{
            scope.row.userType == "1"
            ? "老师"
            : scope.row.userType == "2"
            ? "学生"
            : "本地用户"
            }}
          </template>
        </el-table-column>
      </edu-table>
    </el-dialog>
       
  </div>
</template>
<script>
  import { queryDic } from "common/src/api/dictionary";
  import { getUserInfoListByGroupId } from "common/src/api/user";
  import {
    getListInfoToTutor,
    getStudentInfoToTutor,
    getMasTime,
    getStuTeas,
    cancelRequest,
    deleteManageToTutor,
    getChangeTutorHistory,
    exprotListInfoToTutor
  } from "common/src/api/culture/change";
  import { graduateDegreeList } from "common/src/api/culture/eduProfession";
  import { fileToByteArray } from "common/src/api/culture/change";
  import axios from 'axios'
  import { approvalThrough, approvalReject } from "common/src/api/approval";
  import { throughBatch, rejectBatch } from "common/src/api/studentRegister";
  import ApplyFormToTutor from "./ApplyFormToTutor";
  import PreviewOffice from "common/src/components/common/PreviewOffice.vue"
  import mixin from 'common/src/mixins/index';
  export default {
    name: "DoctorToMasterManage",
    mixins: [mixin],
    components: {
      ApplyFormToTutor,
      PreviewOffice
      
    },
    data: function() {
      return {
        isNull: '',
        ifpreview: false,
        previewfile: {},
        usersUnderGroup: [],
        status: {
          TEACHER_APPROVE: 4,
          COLLEGE_APPROVE: 5,
          KEEP_DEAL_APPROVE: 6,
          CULTURE_APPROVE: 7,
          MANAGE_APPROVE: 8
        },
        currentApproveStatus: 0,
        queryForm: {
          grade: null,
          faculty: null,
          facultyList:[],
          profession: null,
          professionList: [],
          trainingLevel:null,
          trainingCategory: null,
          degreeType: null,
          formLearning: null,
          applyReason: null,
          approvalStatus: null,
          keyWord: null,
          pageSize_: 20,
          pageNum_: 1,
          total_: 0,
          ids:null
        },
        applyReasonList:[],
        approvalStatusList:[],
        options: {
          faculty: [],
          profession: [],
          trainingLevel: [],
          trainingCategory: [],
          degreeType: [],
          formLearning:[],
          applyReason: [],
          approvalStatus: [],
          enrolSeason: [],
          masProfessions: [],
          masTeachers: [],
          opreats:[
            {label: "提交",value: "0"},
            {label: "结束",value: "1"},
            {label: "驳回",value: "2"},
            {label: "通过",value: "3"},
          ]
        },
        students: null,
        currentStudent: null,
        editForm: null,
        indexKey: 0,
        breadPath: {
          label: "转导师",
          key: "0",
          children: [
            {
              key: "1",
              label: ""
            },
            {
              key: "2",
              label: ""
            }
          ]
        },
        applyDetails: {
          applyReason: null,
          reasonDescri: null
        },
        isRead: false,
        isStudent: false,
        //isStudent 为true  studentId 才有值
        studentId:null,
        submitForm: {
          issueNum: null,
          pleaseNum: null,
          applyReason: null,
          masProfession: null,
          masTeacherId: null,
          masGrade: null,
          suggestion: null
        },
        submitRules: {
          applyReason: {
            required: true,
            message: "必须选择申请原因",
            trigger: "change"
          },
          masTeacherId: {
            required: true,
            message: "必须选择硕士导师",
            trigger: "change"
          },
          masGrade: {
            required: true,
            message: "必须选择硕士年级",
            trigger: "change"
          },
          suggestion: {
            validator: this.validateSuggestion,
            trigger: "change"
          }
        },
        currentStudentApproveHistory: [],
        hide: true,
        isShowApproveHistory: true,
        selectStudents: [],
        isTipsShow : false,
        batchForm: {
          suggestion: null
        },
        batchRules: {
          suggestion: {
            required: false,
            message: "必须填写审批意见",
            trigger: "change"
          }
        },
        showUserGroupDialog: false,
        queryUserForm: {
          userName: "",
          pageNum_: 1,
          total: 0,
          pageSize_: 20,
          groupId: ""
        }
      };
    },
    mounted() {
      /*debugger;*/
      let user = this.global.mockUser || this.global.user;
      if (user.type == "2") {
        this.isStudent = true;
        this.studentId = user.uid;
        // 当前角色为学生，给后台传值学生id
        this.queryForm.studentId = this.studentId;
      }
      this.init();
    },
    computed: {
      requireRule() {
        return {
          required: true,
          message: "",
          trigger: "change"
        };
      },
      colSpan() {
        if (this.currentStudent == null) {
          return 6;
        }
        if (
          this.currentStudent.facultyI18n &&
          this.currentStudent.facultyI18n.length >= 8
        ) {
          return 8;
        }
        if (
          this.currentStudent.professionI18n &&
          this.currentStudent.professionI18n.length >= 8
        ) {
          return 8;
        }
        return 6;
      }
    },
    methods: {
      //验证表单审核建议
      validateSuggestion(rule, value, callback) {
        if (this.isReject) {
          if (
            _.isNull(this.submitForm.suggestion) ||
            _.trim(this.submitForm.suggestion) == ""
          ) {
            callback(new Error("必须输入审批意见"));
            return;
          }
        }
        callback();
      },
      init() {
        const data = {
          lang: this.$store.getters.language || "cn",
          type: "allChild",
          keys: [
            "X_YX",
            "X_PYCC",
            "X_PYLB",
            "X_XWLX",
            "X_XXXS",
            "K_ZDYY",
            "K_ZDSH"
          ]
        };
        queryDic(data).then(res => {
          if (res.code === 200) {
            this.fill("faculty", res.data.X_YX);
            this.fill("trainingLevel", res.data.X_PYCC);
            this.fill("trainingCategory", res.data.X_PYLB);
            this.fill("degreeType", res.data.X_XWLX);
            this.fill("formLearning", res.data.X_XXXS);
            this.fill("applyReason", res.data.K_ZDYY);
            this.fill("approvalStatus", res.data.K_ZDSH);
          }
        });
        graduateDegreeList({ pageNum_: 1, pageSize_: 1000, type: 2 }).then(
          res => {
            if (res.code == 200) {
              this.options.masProfessions = res.data.list.map(row => {
                return {
                  label: row.name,
                  value: row.code
                };
              });
            }
          }
        );
        getStuTeas().then(res => {
          if (res.code == 200) {
            for (let key in res.data) {
              this.options.masTeachers.push({
                label: res.data[key] + "(" + key + ")",
                value: key
              });
            }
          }
        });
        this.onSubmit();
      },
      fill(type, data) {
        for (const key in data) {
          this.options[type].push({
            value: key,
            label: data[key]
          });
        }
      },
      reset() {
        this.queryForm.grade = null;
        this.queryForm.faculty = null;
        this.queryForm.facultyList = [];
        this.queryForm.profession = null;
        this.queryForm.professionList = [];
        this.queryForm.trainingLevel = null;
        this.queryForm.trainingCategory = null;
        this.queryForm.degreeType = null;
        this.queryForm.formLearning = null;
        this.queryForm.applyReason = null;
        this.queryForm.approvalStatus = null;
        this.applyReasonList = [];
        this.approvalStatusList = [];
        this.queryForm.keyWord = null;
        this.options.profession.length = 0;
        this.queryForm.ids = "";
        this.onSubmit();
      },
      onSubmit(isFirstPage = true) {
        if (isFirstPage) {
          this.queryForm.pageNum_ = 1;
        }
        // 申请原因、审核状态是多选 后台接受字符串，所以处理一下
        this.queryForm.applyReason = this.applyReasonList.toString();
        this.queryForm.approvalStatus = this.approvalStatusList.toString();
        this.queryForm.faculty = this.queryForm.facultyList.toString();
        this.queryForm.profession = this.queryForm.professionList.toString();
        getListInfoToTutor(this.queryForm).then(res => {
          if (res.code == 200) {
            /*debugger*/
            this.students = res.data.list;
            this.queryForm.total_ = res.data.total_;
          }
        });
      },
      handleCurrentChange(val) {
        this.queryForm.pageSize_ = val.pageSize;
        this.queryForm.pageNum_ = val.pageNum;
        this.onSubmit(false);
      },
      handleApply() {
        this.isNull = '1';
        let user = this.global.mockUser || this.global.user;
        let data =  {
          studentId: user.uid,
          pageSize_ : 1,
          pageNum_ : 10
        };
        getStudentInfoToTutor(data).then(res => {
          if (res.code == 200) {
            if (res.data.list.length == 0) {
              this.$message({
                type: "warning",
                message: "您目前没有导师，无法申请转导师。"
              });
              return;
            }
            let student = res.data.list[0];
            this.currentStudent = {
              studentId: student.studentId,
              studentName: student.studentName,
              facultyI18n: student.facultyI18n,
              professionI18n: student.professionI18n,
              grade: student.grade,
              oldTeacher: student.oldTeacher,
              trainingCategoryI18n: student.trainingCategoryI18n,
              trainingLevelI18n: student.trainingLevelI18n,
              degreeTypeI18n: student.degreeTypeI18n,
              formLearningI18n: student.formLearningI18n
            };
            this.editForm = null;
            this.indexKey = "2";
            this.breadPath.children[1].label = this.$t("message.apply");
          }
        });
      },
      handleBatchCheck() {
        if (this.selectStudents.length == 0) {
          this.$message({
            type: "warning",
            message: "请选择需要审批的申请"
          });
          return;
        }
        if (!this.selectStudents.every(s => s.isApprove == 0)) {
          this.$message({
            type: "warning",
            message: "选中学生必须都是待审核状态"
          });
          return;
        }
        this.$refs.batchApproveDialog.open();
        if (this.$refs.batchForm) {
          this.$refs.batchForm.clearValidate();
        }
        this.batchForm.suggestion = null;
      },
      exprotListToTutor(){

        let res = exprotListInfoToTutor(this.queryForm);
      },
      handleSelectionChange(val) {
        this.selectStudents = val;
        this.queryForm.ids = val.map(index => index.id).toString();
      },
      handleCheck(scope) {
        this.currentApproveStatus = scope.row.approvalStatus;
        //如果审核状态为：导师审核，原导师审核 显示tips,否则不显示
        this.isTipsShow = ["4","5"].includes(this.currentApproveStatus);
        this.isRead = true;
        this.currentStudent = _.cloneDeep(scope.row);
        // this.currentStudent.changeTutorEvidList = scope.row.changeTutorEvid.split(",");
        if(scope.row.changeTutorEvid && scope.row.changeTutorEvid.length > 0) {
        if((scope.row.changeTutorEvid.substring(0,1)).toString() === '[') {
          this.currentStudent.changeTutorEvidList = JSON.parse(scope.row.changeTutorEvid)
        } else {
          let filesList = []
          let evidList = scope.row.changeTutorEvid.split(",")
          evidList.map(files=> {
            filesList.push(
              {
                name: files,
                url: files
              }
            )
          })
          this.currentStudent.changeTutorEvidList = filesList
        }
       }
        this.indexKey = "1";
        this.breadPath.children[0].label = this.$t("message.check");
        //初始化审核表单
        Object.keys(this.submitForm).forEach(key => {
          if (this.currentStudent.hasOwnProperty(key)) {
            this.submitForm[key] =
              typeof this.currentStudent[key] === "number"
                ? this.currentStudent[key].toString()
                : this.currentStudent[key];
          }
        });
        this.getCurrentStudentApproveHistory(this.currentStudent.workflowNo);
        //审核意见置空
        this.submitForm.suggestion = null;
      },
      handleDetail(scope) {
        this.isRead = false;
        this.currentStudent = _.cloneDeep(scope.row);
        /*debugger*/
        this.currentStudent.teacherName = scope.row.oldTeacher;
        // this.currentStudent.changeTutorEvidList = JSON.parse(scope.row.changeTutorEvid);
        if(scope.row.changeTutorEvid && scope.row.changeTutorEvid.length > 0) {
        if((scope.row.changeTutorEvid.substring(0,1)).toString() === '[') {
          this.currentStudent.changeTutorEvidList = JSON.parse(scope.row.changeTutorEvid)
        } else {
          let filesList = []
          let evidList = scope.row.changeTutorEvid.split(",")
          evidList.map(files=> {
            filesList.push(
              {
                name: files,
                url: files
              }
            )
          })
          this.currentStudent.changeTutorEvidList = filesList
        }
       }
        this.indexKey = "1";
        this.breadPath.children[0].label = this.$t("message.detail");
        //是否显示审批进度 如果管理员申请数据 不显示审批进度
        this.isShowApproveHistory = (scope.row.applyType == "3") ? false : true;
        //获取当前学生的审批历史
        this.getCurrentStudentApproveHistory(this.currentStudent.workflowNo);
      },
      handleEdit(scope) {
        /*debugger*/
        this.isRead = false;
        this.currentStudent = scope.row;

        this.currentStudent.oldTeacher = scope.row.oldTeacher
        this.currentStudent.teacherName = scope.row.newTeacherId

        scope.row.oldTeacher = this.currentStudent.oldTeacher;
        scope.row.newTeacherId = this.currentStudent.teacherName;

        this.editForm = scope.row;
        this.indexKey = "2";
        this.breadPath.children[1].label = this.$t("message.edit");
        this.isNull = '0';
      },
      handleDelete(scope) {
        this.$delConfirm().then(() => {
          deleteManageToTutor({ids:[scope.row.id]}).then(res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: this.$t("message.deleteSuccess")
              });
              this.handleReturn();
            }
          });
        });
      },
      // 学生撤回申请
      handleWithdraw(scope) {
        this.$eduConfirm('确认撤回此条申请记录？','提示').then(() => {
          cancelRequest({id:scope.row.id}).then(res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: '撤回成功'
              });
              this.handleReturn();
            }
          });
        });
      },
      //处理批量取消
      handleBatchCancel() {
        this.batchRules.suggestion.required = false;
        this.$refs.batchApproveDialog.close();
      },
      //处理批量拒绝
      handleBatchReject() {
        this.batchRules.suggestion.required = true;
        this.$refs.batchForm.validate(valid => {
          if (!valid) {
            return;
          }
          let data = this.selectStudents.map(r => {
            return {
              no: r.workflowNo,
              content: this.batchForm.suggestion
            };
          });
          rejectBatch(data).then(res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "批量审批驳回"
              });
              this.$refs.batchApproveDialog.close();
              this.queryForm.ids = "";
              this.onSubmit();
            }
          });
        });
      },
      //处理批量通过
      handleBatchPass() {
        this.batchRules.suggestion.required = false;
        let data = this.selectStudents.map(r => {
          return {
            no: r.workflowNo,
            content: this.batchForm.suggestion
          };
        });
        throughBatch(data).then(res => {
          if (res.code == 200) {
            this.$message({
              type: "success",
              message: "批量审批通过"
            });
            this.$refs.batchApproveDialog.close();
            //批量审核通过，重置选择学生id
            this.queryForm.ids = "";
            this.onSubmit();
          }
        });
      },
      handleChangeFaculty() {
        this.options.profession = [];
        this.queryForm.profession = null;
        this.queryForm.professionList = [];
        if (!this.queryForm.facultyList) {
          return;
        }
        const data = {
          lang: this.$store.getters.language || "cn",
          type: "allChild",
          keys: ["G_ZY"],
          filter: {
            prefix: this.queryForm.facultyList,
            specilaCode: "XY2ZY",
            grade: null,
            facultys: this.queryForm.facultyList,
            degreeType: this.queryForm.degreeType
              ? [this.queryForm.degreeType]
              : []
          }
        };
        queryDic(data).then(res => {
          if (res.code === 200) this.fill("profession", res.data.G_ZY);
        });
      },
      handleReturn() {
        this.indexKey = "0";
        this.queryForm.ids = "";
        this.onSubmit();
      },
      handleSave() {
        this.indexKey = "0";
        this.onSubmit();
      },
      handleInput(){
        this.queryForm.ids = "";
      },
      handleReject() {
        this.isReject = true;
        this.$refs.submitForm.validate(valid => {
          if (!valid) {
            return;
          }
          approvalReject({
            no: this.currentStudent.workflowNo,
            content: this.submitForm.suggestion,
            approveAttachment: []
          }).then(res => {
            if (res.code == 200) {
              this.handleReturn();
              this.$message({
                type: "success",
                message: "审核驳回"
              });

            }
          });
        });
      },
      handlePass() {
        this.isReject = false;
        approvalThrough({
          no: this.currentStudent.workflowNo,
          content: this.submitForm.suggestion,
          approveAttachment: []
        }).then(res => {
          if (res.code == 200) {
            this.handleReturn();
            this.$message({
              type: "success",
              message: "审核通过"
            });

          }
        });
      },
     async handleDownLoad(file) {
        this.previewfile = {
          url: file.url,
          name: file.name
        }
            let _this = this
            const resp = await fileToByteArray(this.previewfile)
            _this.loading = true
            if (resp.code === 200) {
                let data = {
                    originalFileName: resp.data.originalFileName,
                    content: resp.data.content
                }
                // 文件从obs转换到预览服务过程2：预览服务接收文件字节数组
                const response = await axios.post('/fileIPreview/fileImport', data, {
                    headers: { 'X-Token': localStorage.getItem('sessionid') || '' }
                })
                if (response.data.code === 200) {
                    let lspdfUrl =
                         '/fileIPreview' + 
                        '/onlinePreview?url=' +
                         'http://10.40.126.227:8012' + 
                        '/demo/' +
                        resp.data.originalFileName
                        window.open(lspdfUrl)
                }  
            }
      },
      moment(val) {
        return moment(val).format("YYYY-MM-DD HH:mm:ss");
      },
      getFileName(path) {
        if (path.indexOf("/") != -1) {
          return path.substring(path.lastIndexOf("/") + 1);
        } else {
          return path;
        }
      },
      getCurrentStudentApproveHistory(workflowNo){
        getChangeTutorHistory(workflowNo).then(res => {
          if (res.code == 200) {
            res.data.forEach((row, index) => {
              row.order_ = index + 1;
            });
            this.currentStudentApproveHistory = res.data;
          }
        });

      },
      hideFrom(){
        this.hide = !this.hide;
      },
      getFacultyLable(key){
        if (key == "学生") {
          return key;
        }
        let tempList = this.options.faculty.filter(x => {
          return x.value == key;
        });
        if(tempList.length == 0){
          return key;
        }
        return tempList[0].label;
      },
      showUserGroup(groupId = "") {
        // this.queryUserForm.groupId = groupId;
        this.$set(this.queryUserForm, "groupId", groupId);
        this.getUserInfoListByGroupId();
        this.showUserGroupDialog = true;
      },
      /**
       * params {groupId 用戶組ID}
       * 根据用户组iD 查询用户
       */
      async getUserInfoListByGroupId() {
        // try {
        //   if (!this.queryUserForm.groupId) {
        //     this.$message({
        //       type: "error",
        //       message: "查询出错, 请重试."
        //     });
        //     return;
        //   }
        //   let { code, data } = await getUserInfoListByGroupId(
        //     this.queryUserForm
        //   );
        //   if (code == 200 && data.list) {
        //     // this.usersUnderGroup = data ? data.list : [];
        //     this.$set(this.usersUnderGroup,data.list)
        //     this.queryUserForm.total = data.total_;
        //   }
        // } catch (err) {
        //   this.$message({
        //     type: "error",
        //     message: "查询出错, 请重试."
        //   });
        // }

        if(!this.queryUserForm.groupId) {
          this.$message({
              type: "error",
              message: "查询出错, 请重试."
            });
            return;
        } else {
         await getUserInfoListByGroupId(this.queryUserForm).then(res=> {
            if(res.code === 200) {
              this.usersUnderGroup = res.data.list
              this.queryUserForm.total = res.data.total_;
            }

          })
        }
      },
      pageChangeDialog(val) {
        this.queryUserForm.pageSize_ = val.pageSize;
        this.queryUserForm.pageNum_ = val.pageNum;
        this.getUserInfoListByGroupId();
      },
    }
  };
</script>

<style lang="scss" scoped>
  .table-detail {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #d2d4d6;
    td {
      border-collapse: collapse;
      border: 1px solid #d2d4d6;
      line-height: 32px;
    }
    .label {
      text-align: right;
      background: #f5f7f9;
      color: #8896a7;
    }
    .textarealabel{
      text-align: right;
      background: #f5f7f9;
      color: #8896a7;
      line-height:105px;
    }
    span {
      margin: 0 10px;
    }
  }
  .el-row-select-top-tips {
    margin-left: 150px;
    text-align: left;
    font-size: 14;
    color: red;
  }
  .el-row-select-top-tips2 {
    margin-left: 210px;
    text-align: left;
    font-size: 14;
    color: red;
  }
  .hideBtn {
    color: #3a7fe8;
    cursor: pointer;
    margin-left: 16px;
  }
</style>
